<template>
	<custom-layout custom-class="custom-layout">
		<!-- 表单 -->
		<wd-form ref="formRef" :model="formData">
			
			<wd-cell-group border>
				<wd-cell title="附属图片" prop="fileUrl" vertical :rules="[{required:true,message:'附属图片'}]">
					<upload v-model="formData.fileUrl" accept="image/*"  theme="image"></upload>
				</wd-cell>
			</wd-cell-group>
		</wd-form>
		<!-- 提交 -->
		<wd-button block size="large" custom-class="submit-button" @click="handleSubmit">提交</wd-button>
		
	</custom-layout>
</template>

<script setup>
	import {
		reactive,
		ref
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		useDictionaryStore,
		useUserStore
	} from '@/store/index.js'
	import {
		engineeringStageReUploadPicture,
	} from '@/api/engineering/detail.js'
	import Upload from '@/packageA/components/upload/upload.vue';
	// 字典仓库
	const dictionaryStore = useDictionaryStore()
	// 用户仓库
	const userStore = useUserStore()
	
	// 表单ref
	const formRef = ref()
	// 表单数据
	const formData = ref({
		fileUrl:[],
	})
	onLoad((option)=>{
		formData.value=JSON.parse(decodeURIComponent(option.row))
		
	})
	// 处理提交
	const handleSubmit = async () => {
		  console.log(formData.value,'formData.value');
		const validateResult = await formRef.value.validate()
		if (!validateResult.valid) return
		uni.showLoading({
			mask: true
		})
		const params = {
			...formData.value,
			
		}
		// if(formData.value.fileUrlList&&formData.value.fileUrlList.length>0) {
		// 	params.fileUrl=formData.value.fileUrlList[0].url
		// }
		engineeringStageReUploadPicture(params).then(()=>{
			uni.navigateBack(); // 返回上一页
			uni.$emit('refresh-examine'); // 触发刷新线索列表
		}).catch((error) => {
			console.log(error);
			
			setTimeout(() => {
				uni.showToast({
					title: '提交失败',
					icon: 'error'
				})
			})
		}).finally(() => {
			uni.hideLoading()
			
		})
		
	}
	
</script>

<style lang="scss" scoped>
	// 自定义布局
	:deep(.custom-layout) {
		background: #F8F8F8;
	}

	// 提交按钮
	:deep(.submit-button) {
		margin: 32rpx;
	}
	.cell-title {
		font-size: 30rpx;
		font-weight: bold;
		margin: 24rpx;
		padding-left: 10rpx;
		position: relative;
	}
	.cell-title:before {
		content: "";
		position: absolute;
		left: -2px;
		top: 15%;
		height: 70%;
		width: 6rpx;
		background-color: #6a9cff;
	}
</style>